package com.kedacom.freedomLabel.base;


import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Toast;

import com.kedacom.freedomLabel.MainApplication;
import com.kedacom.lego.fast.util.ToastUtil;
import com.kedacom.lego.fast.view.LegoFastFragment;
import com.kedacom.lego.fast.view.LegoFastViewModel;
import com.kedacom.lego.util.Utils;
import com.lzscale.scalelib.misclib.Misc;

public abstract class BaseFragment<V extends ViewDataBinding, VM extends LegoFastViewModel>
        extends LegoFastFragment<V, VM> {

    protected V mBinding;
    protected VM mViewModel;
    protected Misc mMisc = Misc.newInstance();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mViewModel = getViewModel();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View root = super.onCreateView(inflater, container, savedInstanceState);
        mBinding = getViewDataBinding();
        return root;
    }

    @Override
    public void showToast(String message) {
        ToastUtil.showFilteredDefaultToast(message);
    }

    @Override
    public void showToast(String message, int toastType) {
        ToastUtil.showFilteredToast(Utils.getApp(), message, toastType, Toast.LENGTH_SHORT, 2);
    }

    @Override
    public int getBindingVariableId() {
        return com.kedacom.freedomLabel.BR.viewModel;
    }

    @Override
    public void onResume() {
        super.onResume();
        ((MainApplication) getActivity().getApplication()).addClickProxy(mBinding.getRoot());
    }

    protected void beep() {
        mMisc.beep();
    }
}